library(knitr)
library(tidyverse)
── Attaching core tidyverse packages ─────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.3 ✔ readr 2.1.4
✔ forcats 1.0.0 ✔ stringr 1.5.0
✔ ggplot2 3.4.3 ✔ tibble 3.2.1
✔ lubridate 1.9.2 ✔ tidyr 1.3.0
✔ purrr 1.0.2 ── Conflicts ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the ]8;;http://conflicted.r-lib.org/conflicted package]8;; to force all conflicts to become errors
library(janitor)
Attaching package: ‘janitor’
The following objects are masked from ‘package:stats’:
chisq.test, fisher.test
library(lubridate)
library(here)
here() starts at C:/Users/thistljy/Documents/ds241_final
library(sf)
Warning: package ‘sf’ was built under R version 4.3.2Linking to GEOS 3.11.2, GDAL 3.7.2, PROJ 9.3.0; sf_use_s2() is TRUE
library(tmap)
Warning: package ‘tmap’ was built under R version 4.3.2Registered S3 method overwritten by 'htmlwidgets':
method from
print.htmlwidget tools:rstudio
Breaking News: tmap 3.x is retiring. Please test v4, e.g. with
remotes::install_github('r-tmap/tmap')
library(tidycensus)
Warning: package ‘tidycensus’ was built under R version 4.3.2
Knitr is used for properly transforming the r notebook into an html file. The tidyverse is used to tidy data using other packages within in such as dplyr. The janitor packages is used to clean up the variable names from the data sets. The lubridate library is used to work with date-times. The here library is used to locate files on the computer to make it easier to load in the data sets. The sf library is used to work with spatial data. The tmap library is used to create interaactive maps. The tidycensus data is used to get data from the U.S Census Bureau data via codes.
racks = st_read((here("data_raw", "Capital_Bikeshare_Locations.geojson"))) |> clean_names()
Reading layer `Capital_Bikeshare_Locations' from data source `C:\Users\thistljy\Documents\ds241_final\data_raw\Capital_Bikeshare_Locations.geojson' using driver `GeoJSON'
Simple feature collection with 754 features and 27 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: -77.36842 ymin: 38.78264 xmax: -76.82554 ymax: 39.12584
Geodetic CRS: WGS 84
census_api_key("9fc5d3792d3a5e922287c3f4e9995118766d50a2")
To install your API key for use in future sessions, run this function with `install = TRUE`.
v2018 = load_variables(2018, "acs5")
df_censcus=get_acs(geography = "tract",
variables=c("vehicles"="B08141_001",
"population" = "B01001_001",
"public_transportion" = "B08006_008"),
state="DC",geometry=TRUE,year=2021)
Getting data from the 2017-2021 5-year ACS
Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
Using FIPS code '11' for state 'DC'
|
| | 0%
|
|========================================================= | 36%
|
|======================================================================================== | 56%
|
|=================================================================================================================================================== | 94%
|
|=============================================================================================================================================================| 100%
For this analysis, we will need the amount of vehiclces used in a specific location in Washington D.c., the population for each area in Washington D.C., and the usage of public transportation in those same areas.
plot(df_censcus)
plot(racks)
Warning: plotting the first 9 out of 27 attributes; use max.plot = 27 to plot all
tmap_mode("view")
tmap mode set to interactive viewing
df_cens=df_censcus %>%
select(-moe) %>%
pivot_wider(names_from = "variable",
values_from = "estimate")|>
mutate(pub_pop = public_transportion / population,
v_pop = vehicles / population)
bike_routes = st_read((here("data_raw", "Signed_Bike_Routes.geojson"))) |> clean_names()
Reading layer `Signed_Bike_Routes' from data source `C:\Users\thistljy\Documents\ds241_final\data_raw\Signed_Bike_Routes.geojson' using driver `GeoJSON'
Simple feature collection with 1024 features and 37 fields
Geometry type: LINESTRING
Dimension: XY
Bounding box: xmin: -77.08773 ymin: 38.8404 xmax: -76.92188 ymax: 38.98634
Geodetic CRS: WGS 84
df_cens_adj = df_cens |> st_transform(4326)
bike_routes = st_as_sf(bike_routes, crs=st_crs(df_cens_adj))
racks = st_as_sf(racks, crs=st_crs(df_cens_adj))
tm_shape(df_cens) +tm_polygons(c("pub_pop", "v_pop"), alpha=.5) + tm_shape(racks) +tm_symbols(size = 0.1, alpha = 0.5) +
tm_shape(bike_routes) + tm_lines(col="blue",lwd=1,alpha= 1)
Here, we see two maps of Washington D.C. The map on the right shows the population proportion of people who use public transportation (excluding taxicub), and on the right we see a the population proportion of people who own vehicles. The assumption is that they use these vehicles as the primary method to commute to work, school, or other transportation needs. On both of the maps, the blue lines represent signed bike routes routes. The assumption is that the primary target areas to put more bike share stations should be where the bikes would be the most accessible to ride on. Signed bike routes mean that those areas are most likely the more safe areas to ride bikes in, and the area around would be most accomadating to bike riders. The circles on each map represents the current bike share locations.
Capital Bike Share Bike Racks: https://opendata.dc.gov/datasets/a1f7acf65795451d89f0a38565a975b3_5/about Bike Share Data: https://capitalbikeshare.com/system-data Signed Bike Routes: https://opendata.dc.gov/explore?collection=Dataset&query=Bike%20Routes